#include <stdio.h>
#include <stdbool.h>
#define Max 100
#define ElementType char 
//循环队列

typedef struct
{
    ElementType arr[Max];
    int front;//队头下标
    int rear;//队尾下标
    int len;
}Queue;

void InitQueue(Queue *q)
{
    for(int i = 0; i < Max; i++)
    {
        q->arr[i] = 0;
    }
    q->front = 0;
    q->rear = 0;
    q->len = 0;
}

//入队列
void Push(Queue *q,ElementType element)
{
    //牺牲一部分空间，以此和队列空的条件做区别
    //if((q->rear + 1) % Max == q->front)
    if(q->len == Max)
    {
        printf("队列已满！\n");
        return;
    }
    q->arr[q->rear++] = element;
    q->rear %= Max;
    q->len++;
}

//出队列
void Pop(Queue *q)
{
    //if(q->front == q->rear)
    if(q->len == 0)
    {
        printf("队列空！\n");
        return;
    }
    q->front++;
    q->front %= Max;
}

ElementType* GetFront(Queue *q)
{
    if(q->front == q->rear)
        return NULL;
    return &q->arr[q->front];
}

bool IsQueueEmpty(Queue *q)
{
    return q->front == q->rear;
}

int main()
{
    Queue q;
    InitQueue(&q);

    for(int i = 0; i < 10; i++)
    {
        Push(&q,i+1);
    }

    while(IsQueueEmpty(&q) == false)
    {
        printf("%d ",*GetFront(&q));
        Pop(&q);
    }
    printf("\n");

    return 0;
}